package patterns.proxy;

import System.machine.FarmMachine;
import patterns.Status.MachineStatus;

public class FarmMachineProxy implements FarmMachine {
    private FarmMachine realMachine;

    public FarmMachineProxy(FarmMachine realMachine) {
        this.realMachine = realMachine;
    }

    @Override
    public String getMachineId() {
        return realMachine.getMachineId();
    }

    @Override
    public String getMachineType() {
        return realMachine.getMachineType();
    }

    @Override
    public void updateStatus(MachineStatus status) {
        System.out.println("[代理] 正在验证状态变更权限...");
        realMachine.updateStatus(status);
    }

    @Override
    public MachineStatus getCurrentStatus() {
        return realMachine.getCurrentStatus();
    }

    @Override
    public void assignTask(String task) {
        System.out.println("[代理] 正在验证任务分配权限...");
        if (!realMachine.getCurrentStatus().isAvailable()) {
            System.out.printf("[代理] 无法分配任务: 农机 %s 当前状态为 %s%n",
                    realMachine.getMachineId(), realMachine.getCurrentStatus().getDescription());
            return;
        }
        realMachine.assignTask(task);
    }

    @Override
    public double getFuelLevel() {
        return realMachine.getFuelLevel();
    }

    @Override
    public void setFuelLevel(double level) {
        System.out.println("[代理] 正在验证油量更新权限...");
        realMachine.setFuelLevel(level);
    }

    @Override
    public String getLocation() {
        return realMachine.getLocation();
    }

    @Override
    public void setLocation(String location) {
        System.out.println("[代理] 正在验证位置更新权限...");
        realMachine.setLocation(location);
    }

    @Override
    public String getCurrentTask() {
        return realMachine.getCurrentTask();
    }

    @Override
    public void displayStatus() {
        System.out.println("[代理] 获取农机状态:");
        realMachine.displayStatus();
    }
}